﻿using System;
using System.Collections.Generic;
using MugenInjection.Delegates;

namespace MugenInjection.Interface.Components
{
    /// <summary>
    ///  Represents the base interface for components that manages the <see cref="IBinding"/>s.
    /// </summary>
    public interface IBindingManagerComponent : IComponent
    {
        /// <summary>
        /// Gets or sets the value, if <c>true</c> cache bindings, otherwise <c>false</c>.
        /// </summary>
        bool IsCacheBinding { get; set; }

        /// <summary>
        /// Searches for a <see cref="IBinding"/> satisfying the specified a <see cref="IBindingContext"/>
        /// </summary>
        /// <param name="bindingContext">The specified <see cref="IBindingContext"/> for search.</param>
        /// <returns>An instance of <see cref="IBinding"/>.</returns>
        IBinding FindBinding(IBindingContext bindingContext);

        /// <summary>
        /// Searches all <see cref="IBinding"/>s satisfying the specified a <see cref="Type"/>
        /// </summary>
        /// <param name="service">The specified <see cref="Type"/> for search.</param>
        /// <returns>A series instances of <see cref="IBinding"/>.</returns>
        IList<IBinding> FindAllBinding(Type service);

        /// <summary>
        /// Searches all <see cref="IBinding"/>s satisfying the specified <see cref="IBindingContext"/>
        /// </summary>
        /// <param name="bindingContext">The specified <see cref="IBindingContext"/> for search.</param>
        /// <returns>A series instances of <see cref="IBinding"/>.</returns>
        IEnumerable<IBinding> FindAllBinding(IBindingContext bindingContext);

        /// <summary>
        /// Selects binding with high priority (check duplicate bindings).
        /// </summary>
        /// <param name="bindingContext">The specified <see cref="IBindingContext"/>.</param>
        /// <param name="bindings">Specifid <see cref="IEnumerator{IBinding}"/> for select <see cref="IBinding"/>.</param>
        /// <returns>An instance of <see cref="IBinding"/>.</returns>
        IBinding GetPriorityBinding(IBindingContext bindingContext, IEnumerable<IBinding> bindings);

        /// <summary>
        /// Creates a self bindable <see cref="IBinding"/>.
        /// </summary>
        /// <param name="service">The specified <see cref="Type"/> to create a self bindable binding.</param>
        /// <param name="activator">The specified factory to create <see cref="IActivator"/>. </param>
        /// <param name="constructorResolver">The specified factory to create <see cref="IConstructorResolver"/>. </param>
        /// <param name="useCache"><c>True</c> - use cache to create an <see cref="IBinding"/>; otherwise <c>false</c>.</param>
        /// <returns>An instance of <see cref="IBinding"/>.</returns>
        IBinding CreateSelfBindable(Type service, Func<IActivator> activator, Func<IConstructorResolver> constructorResolver,
                                    bool useCache);
    }
}